package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.EsDocService;
import com.bawei.system.domain.dto.EsFindDto;
import com.bawei.system.domain.result.PageResult;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.domain.vo.EsDocQueryVo;
import com.bawei.system.domain.vo.EsproductInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "Es文档管理")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;

    @PostMapping("/batchInsertDocs")
    @ApiOperation(value = "批量插入文档")
    public R<Boolean>  batchInsertDocs(@RequestBody List<EsDocInsertVo> esDocInsertVo){
        return esDocService.batchInsertDocs(esDocInsertVo);
    }

    @PostMapping("/queryDocs")
    @ApiOperation(value = "根据传入条件查询Es的文档数据")
    public R  queryDocs(@RequestBody EsDocQueryVo esDocInsertVo){
        return esDocService.queryDocs(esDocInsertVo);
    }

    //完成es-service的删除接口
    @DeleteMapping("/deleteId")
    @ApiOperation(value = "根据传入Ids批量删除数据")
    public R deleteId(@RequestParam List<String> ids,@RequestParam String productInfo){
        esDocService.deleteId(ids,productInfo);
        return R.ok();
    }

    @PostMapping("/find")
    @ApiOperation(value = "普通查询")
    public R<PageResult<EsproductInfoVo>> find(@RequestBody EsFindDto esFindDto){
        PageResult<EsproductInfoVo> list=esDocService.find(esFindDto);
        return R.ok(list);
    }

    //搜索自动补全
    @GetMapping("/querySuggestions/{indexName}")
    @ApiOperation(value = "搜索自动补全")
    public R querySuggestions(@PathVariable(value = "indexName") String indexName,
                              @RequestParam(value = "keyWord") String keyWord,
                              @RequestParam(value = "suggesFiled") String suggesFiled){
        return esDocService.querySuggestions(indexName,keyWord,suggesFiled);
    }


}
